#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>

int sum;

void* worker(void *arg) {
    int l = ((int *)arg)[0];
    int r = ((int *)arg)[1];
    for (int i = l ; i <= r; i++)
        sum += i;
}

int main() {
    pthread_t pid1, pid2;
    int a1[] = {1, 4};
    int a2[] = {5, 99};
    // 分两个线程分别执行
    pthread_create(&pid1, NULL, worker, a1);
    pthread_create(&pid2, NULL, worker, a2);

    pthread_join(pid1, NULL);
    pthread_join(pid2, NULL);

    printf("res = %d", sum);
    return 0;
}